package cj.web.marriageSC.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.web.admin.constants.MemuEnum;
import cj.web.marriageSC.dao.SCOrderItemsDAO;
import cj.web.marriageSC.domain.SCOrderItems;

@Path("/orderItems")
public class SCOrderItemsController{

	private static Logger logger = Logger.getLogger(SCOrderItemsController.class.getName());
	
	@Autowired
	private SCOrderItemsDAO sCOrderItemsDao;

	@Get("show")
	public String show(Model model,@Param("orderId")int orderId, HttpServletRequest request)
	{
		model.add("orderId", orderId);
		model.add("MemuEnum", MemuEnum.marriagescorder);
		return "/views/marriageSC/orderItemsList.vm";
	}
	
	@Post("list")
	public String list(Model model,SCOrderItems orderItems)
	{
		List<SCOrderItems> objs = sCOrderItemsDao.queryByOrderId(orderItems);
		int size = sCOrderItemsDao.sizeByOrderId(orderItems);
		
		JSONObject jo = new JSONObject();
		jo.put("data", objs);
		jo.put("draw", orderItems.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		return "@" + jo.toString();
	}
}
